<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>JavaScript 笔记 | 我的世界</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/notes/favicon.ico">
    <link rel="manifest" href="/notes/manifest.json">
    <meta name="description" content="学习，生活，还有美食~">
    
    <link rel="preload" href="/notes/assets/css/0.styles.8453c794.css" as="style"><link rel="preload" href="/notes/assets/js/app.f19b5e39.js" as="script"><link rel="preload" href="/notes/assets/js/2.69392339.js" as="script"><link rel="preload" href="/notes/assets/js/33.87730e15.js" as="script"><link rel="preload" href="/notes/assets/js/14.e376f3f7.js" as="script"><link rel="prefetch" href="/notes/assets/js/10.4748ef2e.js"><link rel="prefetch" href="/notes/assets/js/11.4ec67c3b.js"><link rel="prefetch" href="/notes/assets/js/12.db234a0a.js"><link rel="prefetch" href="/notes/assets/js/13.0bdeeeea.js"><link rel="prefetch" href="/notes/assets/js/15.873f63d0.js"><link rel="prefetch" href="/notes/assets/js/16.6d650151.js"><link rel="prefetch" href="/notes/assets/js/17.f0bcb5c9.js"><link rel="prefetch" href="/notes/assets/js/18.7dffee3a.js"><link rel="prefetch" href="/notes/assets/js/19.5f0252c4.js"><link rel="prefetch" href="/notes/assets/js/20.abea2681.js"><link rel="prefetch" href="/notes/assets/js/21.252713aa.js"><link rel="prefetch" href="/notes/assets/js/22.c99488d0.js"><link rel="prefetch" href="/notes/assets/js/23.3839292f.js"><link rel="prefetch" href="/notes/assets/js/24.9cc2f325.js"><link rel="prefetch" href="/notes/assets/js/25.e9dcd2f1.js"><link rel="prefetch" href="/notes/assets/js/26.31898ae6.js"><link rel="prefetch" href="/notes/assets/js/27.88db2371.js"><link rel="prefetch" href="/notes/assets/js/28.2d29c56c.js"><link rel="prefetch" href="/notes/assets/js/29.a0b42251.js"><link rel="prefetch" href="/notes/assets/js/3.48b2b659.js"><link rel="prefetch" href="/notes/assets/js/30.9b38a2bb.js"><link rel="prefetch" href="/notes/assets/js/31.d374da8e.js"><link rel="prefetch" href="/notes/assets/js/32.7868c3f3.js"><link rel="prefetch" href="/notes/assets/js/34.5a5b6c6e.js"><link rel="prefetch" href="/notes/assets/js/35.1deedbd4.js"><link rel="prefetch" href="/notes/assets/js/36.d39f2b24.js"><link rel="prefetch" href="/notes/assets/js/37.d87637b4.js"><link rel="prefetch" href="/notes/assets/js/38.d118907c.js"><link rel="prefetch" href="/notes/assets/js/39.9f2c8514.js"><link rel="prefetch" href="/notes/assets/js/4.161aee82.js"><link rel="prefetch" href="/notes/assets/js/40.917feb30.js"><link rel="prefetch" href="/notes/assets/js/41.78e1b969.js"><link rel="prefetch" href="/notes/assets/js/42.cd6ac9d4.js"><link rel="prefetch" href="/notes/assets/js/43.961a438d.js"><link rel="prefetch" href="/notes/assets/js/44.ef1661d7.js"><link rel="prefetch" href="/notes/assets/js/45.b89cd059.js"><link rel="prefetch" href="/notes/assets/js/46.8ca9e560.js"><link rel="prefetch" href="/notes/assets/js/47.a35bec74.js"><link rel="prefetch" href="/notes/assets/js/48.953bb15e.js"><link rel="prefetch" href="/notes/assets/js/49.ae614c87.js"><link rel="prefetch" href="/notes/assets/js/5.ef4783db.js"><link rel="prefetch" href="/notes/assets/js/50.a9fbc190.js"><link rel="prefetch" href="/notes/assets/js/51.12ae367b.js"><link rel="prefetch" href="/notes/assets/js/52.57a5efe4.js"><link rel="prefetch" href="/notes/assets/js/53.861eb65b.js"><link rel="prefetch" href="/notes/assets/js/54.3bc1c9a1.js"><link rel="prefetch" href="/notes/assets/js/55.f724b26c.js"><link rel="prefetch" href="/notes/assets/js/56.02e48e7a.js"><link rel="prefetch" href="/notes/assets/js/6.72ed1ea6.js"><link rel="prefetch" href="/notes/assets/js/7.f1e39dec.js"><link rel="prefetch" href="/notes/assets/js/8.84b75613.js"><link rel="prefetch" href="/notes/assets/js/9.e1cd5390.js">
    <link rel="stylesheet" href="/notes/assets/css/0.styles.8453c794.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/notes/" class="home-link router-link-active"><img src="/notes/images/fish.gif" alt="我的世界" class="logo"> <span class="site-name can-hide">我的世界</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/notes/notes/" class="nav-link router-link-active">🎓 学习</a></div><div class="nav-item"><a href="/notes/life/" class="nav-link">🏸 生活</a></div> <a href="https://gitee.com/zgj6" target="_blank" rel="noopener noreferrer" class="repo-link">
    git
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/notes/notes/" class="nav-link router-link-active">🎓 学习</a></div><div class="nav-item"><a href="/notes/life/" class="nav-link">🏸 生活</a></div> <a href="https://gitee.com/zgj6" target="_blank" rel="noopener noreferrer" class="repo-link">
    git
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p title="学习笔记" class="sidebar-heading open"><span>学习笔记</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/notes/notes/" aria-current="page" title="目录 · 分类" class="sidebar-link">目录 · 分类</a></li><li><a href="/notes/notes/css_note.html" title="CSS 基础用法收集" class="sidebar-link">CSS 基础用法收集</a></li><li><a href="/notes/notes/fe-effects-collection.html" title="前端实用特效 · Demo" class="sidebar-link">前端实用特效 · Demo</a></li><li><a href="/notes/notes/git-notes.html" title="git 笔记" class="sidebar-link">git 笔记</a></li><li><a href="/notes/notes/js-notes.html" aria-current="page" title="JavaScript 笔记" class="active sidebar-link">JavaScript 笔记</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/notes/notes/js-notes.html#js-浅拷贝与深拷贝" title="JS 浅拷贝与深拷贝" class="sidebar-link">JS 浅拷贝与深拷贝</a></li><li class="sidebar-sub-header"><a href="/notes/notes/js-notes.html#节流与防抖" title="节流与防抖" class="sidebar-link">节流与防抖</a></li><li class="sidebar-sub-header"><a href="/notes/notes/js-notes.html#ajax、原生-xhr、jsonp" title="AJAX、原生 XHR、JSONP" class="sidebar-link">AJAX、原生 XHR、JSONP</a></li><li class="sidebar-sub-header"><a href="/notes/notes/js-notes.html#动态加载css" title="动态加载CSS" class="sidebar-link">动态加载CSS</a></li><li class="sidebar-sub-header"><a href="/notes/notes/js-notes.html#页面加载后执行" title="页面加载后执行" class="sidebar-link">页面加载后执行</a></li><li class="sidebar-sub-header"><a href="/notes/notes/js-notes.html#使用sublime如何批量修改-追加-页面底部的js" title="使用Sublime如何批量修改（追加）页面底部的JS" class="sidebar-link">使用Sublime如何批量修改（追加）页面底部的JS</a></li><li class="sidebar-sub-header"><a href="/notes/notes/js-notes.html#jquery-自定义css" title="jquery 自定义CSS" class="sidebar-link">jquery 自定义CSS</a></li><li class="sidebar-sub-header"><a href="/notes/notes/js-notes.html#jquery-追加元素" title="jquery 追加元素" class="sidebar-link">jquery 追加元素</a></li><li class="sidebar-sub-header"><a href="/notes/notes/js-notes.html#jquery-获取元素高度" title="jquery 获取元素高度" class="sidebar-link">jquery 获取元素高度</a></li><li class="sidebar-sub-header"><a href="/notes/notes/js-notes.html#url查询字符解析器" title="url查询字符解析器" class="sidebar-link">url查询字符解析器</a></li><li class="sidebar-sub-header"><a href="/notes/notes/js-notes.html#url-query-param-解析器" title="url query param 解析器" class="sidebar-link">url query param 解析器</a></li><li class="sidebar-sub-header"><a href="/notes/notes/js-notes.html#javascript对象复制" title="JavaScript对象复制" class="sidebar-link">JavaScript对象复制</a></li><li class="sidebar-sub-header"><a href="/notes/notes/js-notes.html#ie" title="IE" class="sidebar-link">IE</a></li><li class="sidebar-sub-header"><a href="/notes/notes/js-notes.html#使用html的方式进行页面跳转" title="使用HTML的方式进行页面跳转" class="sidebar-link">使用HTML的方式进行页面跳转</a></li><li class="sidebar-sub-header"><a href="/notes/notes/js-notes.html#google-analysis" title="Google Analysis" class="sidebar-link">Google Analysis</a></li><li class="sidebar-sub-header"><a href="/notes/notes/js-notes.html#获取该元素相对于视口的坐标" title="获取该元素相对于视口的坐标" class="sidebar-link">获取该元素相对于视口的坐标</a></li><li class="sidebar-sub-header"><a href="/notes/notes/js-notes.html#htmlcollection类数组对象转换为数组" title="HTMLCollection类数组对象转换为数组" class="sidebar-link">HTMLCollection类数组对象转换为数组</a></li></ul></li><li><a href="/notes/notes/nodejs-notes.html" title="Node.js学习" class="sidebar-link">Node.js学习</a></li><li><a href="/notes/notes/ports.html" title="端口占用查询" class="sidebar-link">端口占用查询</a></li><li><a href="/notes/notes/vuepress.html" title="vuepress使用中遇到的问题" class="sidebar-link">vuepress使用中遇到的问题</a></li><li><a href="/notes/notes/windows.html" title="Windows" class="sidebar-link">Windows</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p title="JavaScript 高程笔记" class="sidebar-heading"><span>JavaScript 高程笔记</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p title="HTTP" class="sidebar-heading"><span>HTTP</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p title="微信小程序" class="sidebar-heading"><span>微信小程序</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p title="TS" class="sidebar-heading"><span>TS</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p title="Vite" class="sidebar-heading"><span>Vite</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p title="interviewquestion" class="sidebar-heading"><span>interviewquestion</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p title="AI" class="sidebar-heading"><span>AI</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p title="UE" class="sidebar-heading"><span>UE</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="javascript-笔记"><a href="#javascript-笔记" class="header-anchor">#</a> JavaScript 笔记</h1> <h2 id="js-浅拷贝与深拷贝"><a href="#js-浅拷贝与深拷贝" class="header-anchor">#</a> <a href="/notes/notes/js/js-object-clone.html">JS 浅拷贝与深拷贝</a></h2> <h2 id="节流与防抖"><a href="#节流与防抖" class="header-anchor">#</a> <a href="/notes/notes/js/js-throttle-debounce.html">节流与防抖</a></h2> <h2 id="ajax、原生-xhr、jsonp"><a href="#ajax、原生-xhr、jsonp" class="header-anchor">#</a> <a href="/files/js/ajax-demo">AJAX、原生 XHR、JSONP</a></h2> <h2 id="动态加载css"><a href="#动态加载css" class="header-anchor">#</a> 动态加载CSS</h2> <div class="language-javascript extra-class"><pre class="language-javascript"><code>
<span class="token function">loadAltCss</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">function</span> <span class="token function">loadAltCss</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// 根据页面地址选择响相应的css</span>
    <span class="token keyword">var</span> url <span class="token operator">=</span> window<span class="token punctuation">.</span>location<span class="token punctuation">.</span>href<span class="token punctuation">;</span>
    <span class="token keyword">var</span> pages <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">'pro.aspx'</span><span class="token punctuation">,</span> <span class="token string">'recruitment.aspx'</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token keyword">var</span> loadAlt <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
    <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">var</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;=</span> pages<span class="token punctuation">.</span>length<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>url<span class="token punctuation">.</span><span class="token function">match</span><span class="token punctuation">(</span>pages<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            loadAlt <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
            <span class="token keyword">break</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">if</span> <span class="token punctuation">(</span>loadAlt<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">loadCss</span><span class="token punctuation">(</span><span class="token string">'./Css/c_mbxs_alt.css'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
        <span class="token function">loadCss</span><span class="token punctuation">(</span><span class="token string">'./Css/c_mbxs.css'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">function</span> <span class="token function">loadCss</span><span class="token punctuation">(</span><span class="token parameter">url</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token comment">/*JavaScript动态加载Css文件*/</span>
    <span class="token keyword">var</span> cssNode <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">createElement</span><span class="token punctuation">(</span><span class="token string">'link'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    cssNode<span class="token punctuation">.</span>rel <span class="token operator">=</span> <span class="token string">'stylesheet'</span><span class="token punctuation">;</span>
    cssNode<span class="token punctuation">.</span>type <span class="token operator">=</span> <span class="token string">'text/css'</span><span class="token punctuation">;</span>
    cssNode<span class="token punctuation">.</span>media <span class="token operator">=</span> <span class="token string">'screen'</span><span class="token punctuation">;</span>
    cssNode<span class="token punctuation">.</span>href <span class="token operator">=</span> url <span class="token operator">+</span> <span class="token string">'?t='</span> <span class="token operator">+</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">/*附带时间参数，防止缓存*/</span>
    document<span class="token punctuation">.</span>head<span class="token punctuation">.</span><span class="token function">appendChild</span><span class="token punctuation">(</span>cssNode<span class="token punctuation">)</span><span class="token punctuation">;</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'Load CSS: '</span><span class="token operator">+</span>url<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre></div><h2 id="页面加载后执行"><a href="#页面加载后执行" class="header-anchor">#</a> 页面加载后执行</h2> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token comment">// 页面元素完全加载之后执行</span>
window<span class="token punctuation">.</span><span class="token function-variable function">onload</span> <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token function">$</span><span class="token punctuation">(</span>window<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">load</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// 页面框架加载完成后执行</span>
<span class="token function">$</span><span class="token punctuation">(</span>document<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">ready</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre></div><h2 id="使用sublime如何批量修改-追加-页面底部的js"><a href="#使用sublime如何批量修改-追加-页面底部的js" class="header-anchor">#</a> 使用Sublime如何批量修改（追加）页面底部的JS</h2> <p>使用Sublime，Ctrl+Shift+F，第一个参数<code>&lt;/body&gt;</code>，第二个参数<code>&lt;open folders&gt;</code>，第三个参数：</p> <div class="language-html extra-class"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>text/javascript<span class="token punctuation">&quot;</span></span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>Js/addEffects.js<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token script"></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
</code></pre></div><h2 id="jquery-自定义css"><a href="#jquery-自定义css" class="header-anchor">#</a> jquery 自定义CSS</h2> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token function">$</span><span class="token punctuation">(</span><span class="token string">'.n_content_right_name_r a:last'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">css</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token string">&quot;color&quot;</span><span class="token operator">:</span><span class="token string">&quot;#aa8129&quot;</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token function">$</span><span class="token punctuation">(</span><span class="token string">'.bk6_n_content_right_name_r a:last'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">css</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token string">&quot;color&quot;</span><span class="token operator">:</span><span class="token string">&quot;#aa8129&quot;</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">var</span> color <span class="token operator">=</span> <span class="token function">$</span><span class="token punctuation">(</span><span class="token string">'.index_dy_box1 p'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">attr</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token string">&quot;class&quot;</span><span class="token operator">:</span><span class="token string">&quot;a1&quot;</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
color<span class="token punctuation">.</span><span class="token function">each</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">i</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>i<span class="token operator">%</span><span class="token number">2</span><span class="token operator">==</span><span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token function">$</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">attr</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token string">&quot;class&quot;</span><span class="token operator">:</span><span class="token string">&quot;a3&quot;</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>i<span class="token operator">%</span><span class="token number">3</span><span class="token operator">==</span><span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token function">$</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">attr</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token string">&quot;class&quot;</span><span class="token operator">:</span><span class="token string">&quot;a5&quot;</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre></div><h2 id="jquery-追加元素"><a href="#jquery-追加元素" class="header-anchor">#</a> jquery 追加元素</h2> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token function">$</span><span class="token punctuation">(</span><span class="token string">'.n_main'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">'&lt;div class=&quot;placeholder122&quot;&gt;&lt;/div&gt;'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">$</span><span class="token punctuation">(</span><span class="token string">'.n_main'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">'&lt;div class=&quot;add_left122&quot;&gt;&lt;/div&gt;&lt;div class=&quot;add_right122&quot;&gt;&lt;/div&gt;'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">$</span><span class="token punctuation">(</span><span class="token string">'.n_main'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">'&lt;div class=&quot;add_bottom122&quot;&gt;&lt;img src=&quot;http://0.rc.xiniu.com/g2/M00/61/DD/CgAGe1qeU0SAPfBnAAAMZ1rzPMs531.png&quot;&gt;&lt;/div&gt;'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h2 id="jquery-获取元素高度"><a href="#jquery-获取元素高度" class="header-anchor">#</a> jquery 获取元素高度</h2> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">var</span> mainHight <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">&quot;ea_c&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span>offsetHeight<span class="token punctuation">;</span>   <span class="token comment">// '567'</span>
<span class="token keyword">var</span> height <span class="token operator">=</span> <span class="token function">$</span><span class="token punctuation">(</span><span class="token string">'#ea_c'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">css</span><span class="token punctuation">(</span><span class="token string">'height'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token comment">// '567px'</span>
</code></pre></div><h2 id="url查询字符解析器"><a href="#url查询字符解析器" class="header-anchor">#</a> url查询字符解析器</h2> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">var</span> url <span class="token operator">=</span> <span class="token string">&quot;https://github.com/kk?tab=stars&amp;assetId=311&amp;page=DETAIL&amp;projectPhase=2&quot;</span><span class="token punctuation">;</span>
<span class="token keyword">function</span> <span class="token function">splitUrl</span><span class="token punctuation">(</span><span class="token parameter">url</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> url <span class="token operator">!==</span> <span class="token string">&quot;string&quot;</span><span class="token punctuation">)</span> <span class="token keyword">return</span><span class="token punctuation">;</span>
    <span class="token keyword">var</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
    url<span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">&quot;?&quot;</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">&quot;&amp;&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token parameter">item</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
        <span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span>key<span class="token punctuation">,</span> value<span class="token punctuation">]</span> <span class="token operator">=</span> item<span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">&quot;=&quot;</span><span class="token punctuation">)</span>
        obj<span class="token punctuation">[</span>arr<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">]</span> <span class="token operator">=</span> arr<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token function">splitUrl</span><span class="token punctuation">(</span>url<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h2 id="url-query-param-解析器"><a href="#url-query-param-解析器" class="header-anchor">#</a> url query param 解析器</h2> <div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">/**
 * 解析url query参数
 * @example ?id=12345&amp;a=b
 * @return Object {id:12345,a:b}
 */</span>
<span class="token keyword">export</span> <span class="token keyword">function</span> <span class="token function">urlParse</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">let</span> url <span class="token operator">=</span> window<span class="token punctuation">.</span>location<span class="token punctuation">.</span>search<span class="token punctuation">;</span>
  <span class="token keyword">let</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
  <span class="token keyword">let</span> reg <span class="token operator">=</span> <span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">[?&amp;][^?&amp;]+=[^?&amp;]+</span><span class="token regex-delimiter">/</span><span class="token regex-flags">g</span></span><span class="token punctuation">;</span>
  <span class="token keyword">let</span> arr <span class="token operator">=</span> url<span class="token punctuation">.</span><span class="token function">match</span><span class="token punctuation">(</span>reg<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token comment">// ['?id=12345', '&amp;a=b']</span>
  <span class="token keyword">if</span> <span class="token punctuation">(</span>arr<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    arr<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">item</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
      <span class="token keyword">let</span> tempArr <span class="token operator">=</span> item<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">'='</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">let</span> key <span class="token operator">=</span> <span class="token function">decodeURIComponent</span><span class="token punctuation">(</span>tempArr<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">let</span> val <span class="token operator">=</span> <span class="token function">decodeURIComponent</span><span class="token punctuation">(</span>tempArr<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      obj<span class="token punctuation">[</span>key<span class="token punctuation">]</span> <span class="token operator">=</span> val<span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
  <span class="token keyword">return</span> obj<span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
</code></pre></div><h2 id="javascript对象复制"><a href="#javascript对象复制" class="header-anchor">#</a> JavaScript对象复制</h2> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">var</span> oldObj <span class="token operator">=</span> <span class="token punctuation">{</span>
    aa<span class="token operator">:</span><span class="token number">1</span>
<span class="token punctuation">}</span>
<span class="token keyword">var</span> newObj <span class="token operator">=</span> Object<span class="token punctuation">.</span><span class="token function">assign</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> oldObj<span class="token punctuation">)</span>
</code></pre></div><h2 id="ie"><a href="#ie" class="header-anchor">#</a> IE</h2> <div class="language-html extra-class"><pre class="language-html"><code><span class="token comment">&lt;!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 --&gt;</span>
    <span class="token comment">&lt;!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 --&gt;</span>
    <span class="token comment">&lt;!--[if lt IE 9]&gt;
    &lt;script src=&quot;https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://cdn.bootcss.com/respond./static/js/1.4.2/respond.min.js&quot;&gt;&lt;/script&gt;
    &lt;![endif]--&gt;</span>

</code></pre></div><h2 id="使用html的方式进行页面跳转"><a href="#使用html的方式进行页面跳转" class="header-anchor">#</a> 使用HTML的方式进行页面跳转</h2> <div class="language-html extra-class"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta</span> <span class="token attr-name">http-equiv</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>refresh<span class="token punctuation">&quot;</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>0;http://www.bing.com<span class="token punctuation">&quot;</span></span><span class="token punctuation">/&gt;</span></span>
</code></pre></div><div class="language-js extra-class"><pre class="language-js"><code>location<span class="token punctuation">.</span>href<span class="token operator">=</span><span class="token string">&quot;/&quot;</span>
</code></pre></div><h2 id="google-analysis"><a href="#google-analysis" class="header-anchor">#</a> Google Analysis</h2> <div class="language-html extra-class"><pre class="language-html"><code><span class="token comment">&lt;!-- Global site tag (gtag.js) - Google Analytics --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">async</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>https://www.googletagmanager.com/gtag/js?id=UA-#########-#<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token script"></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript">
  window<span class="token punctuation">.</span>dataLayer <span class="token operator">=</span> window<span class="token punctuation">.</span>dataLayer <span class="token operator">||</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
  <span class="token keyword">function</span> <span class="token function">gtag</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>dataLayer<span class="token punctuation">.</span><span class="token function">push</span><span class="token punctuation">(</span>arguments<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token punctuation">}</span>
  <span class="token function">gtag</span><span class="token punctuation">(</span><span class="token string">'js'</span><span class="token punctuation">,</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token function">gtag</span><span class="token punctuation">(</span><span class="token string">'config'</span><span class="token punctuation">,</span> <span class="token string">'UA-#########-#'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
</code></pre></div><div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">// Google 统计</span>
<span class="token function">$</span><span class="token punctuation">(</span>document<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">ready</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
  <span class="token keyword">var</span> ga <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">createElement</span><span class="token punctuation">(</span><span class="token string">'script'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  ga<span class="token punctuation">.</span>type <span class="token operator">=</span> <span class="token string">'text/javascript'</span><span class="token punctuation">;</span>
  ga<span class="token punctuation">.</span>async <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
  ga<span class="token punctuation">.</span>src <span class="token operator">=</span> <span class="token string">'https://www.googletagmanager.com/gtag/js?id=UA-#########-#'</span><span class="token punctuation">;</span>
  document<span class="token punctuation">.</span>body<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span>ga<span class="token punctuation">)</span><span class="token punctuation">;</span>
  window<span class="token punctuation">.</span>dataLayer <span class="token operator">=</span> window<span class="token punctuation">.</span>dataLayer <span class="token operator">||</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
  <span class="token keyword">function</span> <span class="token function">gtag</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>dataLayer<span class="token punctuation">.</span><span class="token function">push</span><span class="token punctuation">(</span>arguments<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token punctuation">}</span>
  <span class="token function">gtag</span><span class="token punctuation">(</span><span class="token string">'js'</span><span class="token punctuation">,</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token function">gtag</span><span class="token punctuation">(</span><span class="token string">'config'</span><span class="token punctuation">,</span> <span class="token string">'UA-#########-#'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre></div><div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">// min</span>
<span class="token function">$</span><span class="token punctuation">(</span>document<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">ready</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token keyword">function</span> <span class="token function">b</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>dataLayer<span class="token punctuation">.</span><span class="token function">push</span><span class="token punctuation">(</span>arguments<span class="token punctuation">)</span><span class="token punctuation">}</span><span class="token keyword">var</span> a<span class="token operator">=</span>document<span class="token punctuation">.</span><span class="token function">createElement</span><span class="token punctuation">(</span><span class="token string">&quot;script&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>a<span class="token punctuation">.</span>type<span class="token operator">=</span><span class="token string">&quot;text/javascript&quot;</span><span class="token punctuation">;</span>a<span class="token punctuation">.</span>async<span class="token operator">=</span><span class="token operator">!</span><span class="token number">0</span><span class="token punctuation">;</span>a<span class="token punctuation">.</span>src<span class="token operator">=</span><span class="token string">&quot;https://www.googletagmanager.com/gtag/js?id=UA-#########-#&quot;</span><span class="token punctuation">;</span>document<span class="token punctuation">.</span>body<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>window<span class="token punctuation">.</span>dataLayer<span class="token operator">=</span>window<span class="token punctuation">.</span>dataLayer<span class="token operator">||</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token function">b</span><span class="token punctuation">(</span><span class="token string">&quot;js&quot;</span><span class="token punctuation">,</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token function">b</span><span class="token punctuation">(</span><span class="token string">&quot;config&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;UA-#########-#&quot;</span><span class="token punctuation">)</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h2 id="获取该元素相对于视口的坐标"><a href="#获取该元素相对于视口的坐标" class="header-anchor">#</a> 获取该元素相对于视口的坐标</h2> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">let</span> rect <span class="token operator">=</span> Element<span class="token punctuation">.</span><span class="token function">getBoundingClientRect</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><h2 id="htmlcollection类数组对象转换为数组"><a href="#htmlcollection类数组对象转换为数组" class="header-anchor">#</a> HTMLCollection类数组对象转换为数组</h2> <p>参考：https://stackoverflow.com/a/222847</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token class-name">Array</span><span class="token punctuation">.</span>prototype<span class="token punctuation">.</span><span class="token function">slice</span><span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span> htmlCollection <span class="token punctuation">)</span>
</code></pre></div><p>will have the same effect using &quot;native&quot; code.</p> <p><strong>Edit</strong></p> <p>Since this gets a lot of views, note (per @oriol's comment) that the following more concise expression is <em>effectively</em> equivalent:</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">slice</span><span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span>htmlCollection<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><p>But note per @JussiR's comment, that unlike the &quot;verbose&quot; form, it  does create an empty, unused, and indeed unusable array instance in the  process.  What compilers do about this is outside the programmer's ken.</p> <p><strong>Edit</strong></p> <p>Since ECMAScript 2015 (ES 6) there is also <a href="http://ecma-international.org/ecma-262/8.0/#sec-array.from" target="_blank" rel="noopener noreferrer"><em>Array.from</em><span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>:</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">var</span> arr <span class="token operator">=</span> Array<span class="token punctuation">.</span><span class="token function">from</span><span class="token punctuation">(</span>htmlCollection<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><p><strong>Edit</strong></p> <p>ECMAScript 2015 also provides the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax" target="_blank" rel="noopener noreferrer">spread operator<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>, which is functionally equivalent to <code>Array.from</code> (although note that <code>Array.from</code> supports a mapping function as the second argument).</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token operator">...</span>htmlCollection<span class="token punctuation">]</span><span class="token punctuation">;</span>
</code></pre></div><p>I've confirmed that both of the above work on <code>NodeList</code>.</p> <p>A performance comparison for the mentioned methods: http://jsben.ch/h2IFA</p></div> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2023-4-5 17:45:19</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/notes/notes/git-notes.html" class="prev">git 笔记</a></span> <span class="next"><a href="/notes/notes/nodejs-notes.html">Node.js学习</a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----><div id="live2d-widget" class="live2d-widget-container" style="position:fixed;right:65px;bottom:0px;width:135px;height:300px;z-index:99999;opacity:0.8;pointer-events:none;"><canvas id="live2d_canvas" width="135" height="300" class="live2d_canvas" style="position:absolute;left:0px;top:0px;width:135px;height:300px;"></canvas></div></div></div>
    <script src="/notes/assets/js/app.f19b5e39.js" defer></script><script src="/notes/assets/js/2.69392339.js" defer></script><script src="/notes/assets/js/33.87730e15.js" defer></script><script src="/notes/assets/js/14.e376f3f7.js" defer></script>
  </body>
</html>
